/*++
Module Name:

    ReadWriteRequest.h

Abstract:

    This module contains the type definitions for the HID Read/write request
    completion callback class.
--*/

#pragma once

class CAsyncCallback
{
public:
	virtual void OnAsyncReadCallback(BYTE* buffer, ULONG length, void *context) = 0;
};

// This class implements IRequestCallbackRequestCompletion callback
// to get the request completion notification when request is sent down the
// stack. 

class CReadWriteRequest :
    public CComObjectRoot,
    public IRequestCallbackRequestCompletion
{
public:
    CReadWriteRequest();
    virtual ~CReadWriteRequest();

    DECLARE_NOT_AGGREGATABLE(CReadWriteRequest)

    BEGIN_COM_MAP(CReadWriteRequest)
        COM_INTERFACE_ENTRY(IRequestCallbackRequestCompletion)
    END_COM_MAP()

//
// Public methods
//
public:

    HRESULT InitializeRequest(IWDFDevice *pWdfDevice, CAsyncCallback* pCallback);
    HRESULT UninitializeRequest();

    //Create and send read request down the stack
    HRESULT CreateAndSendReadRequest(void *context = NULL);

    //Create and send write request down the stack
    HRESULT CreateAndSendWriteRequest(BYTE* buffer, ULONG bufferSize, void *context = NULL);

	//Create and send IOCTL request down the stack
    HRESULT CreateAndSendIOCTLRequest(ULONG ulCode, BYTE* buffer, ULONG bufferSize, void *context = NULL);

    //Cancel and stop pending request
    HRESULT CancelAndStopPendingRequest();

    //
    // IRequestCallbackRequestCompletion method
    //

    virtual void STDMETHODCALLTYPE OnCompletion( __in IWDFIoRequest*                 FxRequest,
                                                 __in IWDFIoTarget*                  FxIoTarget,
                                                 __in IWDFRequestCompletionParams*   CompletionParams,
                                                 __in PVOID                          Context
                                                );
// Private data members.
private:
    
    // All the one-time setup HID Request parameters
    CComPtr<IWDFDevice>             m_pHidWdfDevice;
    CComPtr<IWDFDriver>             m_pHidWdfDriver;
    CComPtr<IWDFDriverCreatedFile>  m_pHidWdfFile;
    CComPtr<IWDFIoTarget>           m_pHidWdfIoTarget;

    CComPtr<IWDFIoRequest>          m_pHidWdfIoRequest; // UMDF Framework Request object
    CAsyncCallback*                 m_pParentCallback;  // Parent callback

    BYTE    m_buffer[READ_BUFFER_SIZE]; // Buffer for read result
    ULONG   m_bytesRead;

    BOOL m_fResend; // Flag that indicates if a resend is needed
};
